package com.huluobo.a2307douyindemo.mine

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.huluobo.a2307douyindemo.R
import com.huluobo.a2307douyindemo.adapter.LikeAdapter
import com.huluobo.a2307douyindemo.databinding.FragmentLikeBinding
import com.huluobo.lib_base.mvvm.BaseFragment

class LikeFragment : BaseFragment<FragmentLikeBinding, MineViewModel>() {
    private lateinit var likeAdapter: LikeAdapter
    override fun initData() {
        vm.getLikeVideosSuccess.observe(this) {
            likeAdapter.data.clear()
            likeAdapter.data.addAll(it)
            likeAdapter.notifyDataSetChanged()
        }

        vm.unLikeSuccess.observe(this) {
            vm.getLikeVideos()
        }
    }

    override fun onResume() {
        super.onResume()
        vm.getLikeVideos()
    }

    override fun initView() {
        binding.likeRv.layoutManager = GridLayoutManager(requireContext(), 2)
        likeAdapter = LikeAdapter()
        binding.likeRv.adapter = likeAdapter

        likeAdapter.addChildClickViewIds(R.id.item_like_delete_iv)
        likeAdapter.setOnItemChildClickListener { adapter, view, position ->
            when (view.id) {
                R.id.item_like_delete_iv -> {
                    vm.unLikeVideo(likeAdapter.data[position].id)
                }
            }
        }
    }
}